import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {
        if(args.length < 1) {
            System.out.println("USAGE:");
            System.out.println("fxosinstall <path of package>");
            System.exit(2);
        }

        if(!AdbWrapper.forwardPort(6000)) {
            System.out.println("Unable to forward port!");
            System.exit(1);
        }

        System.out.println("Check device screen! Waiting for debugger to connect...");
        DebuggerTransport transport = new DebuggerTransport("localhost", 6000);
        if(!transport.open()) {
            System.out.println("Unable to open debugger connection!");
            System.exit(1);
        }

        transport.receiveAnswer();    // ignore first answer
        AppInstaller installer = new AppInstaller(transport);
        installer.installApp(args[0]);
        System.out.println("Application successfully installed");
        transport.close();
    }
}
